import {
  Mesh,
  LineBasicMaterial,
  EdgesGeometry,
  LineSegments,
  Material,
  type ColorRepresentation,
} from "three";

export function DrawMeshWireframeLines(
  mesh: Mesh,
  depthTest: boolean,
  color: ColorRepresentation
) {
  const lineMaterial = new LineBasicMaterial({ color: color });
  mesh.traverse((child) => {
    if (child instanceof Mesh && child.geometry) {
      let edges = new EdgesGeometry(child.geometry);
      let lines = new LineSegments(edges, lineMaterial);
      if (!depthTest) {
        lines.material.depthTest = false;
        lines.material.transparent = true; //透明才能被看到
        lines.material.opacity = 0.5;
      }
      mesh.add(lines);
    }
  });
  if (!depthTest) {
    (mesh.material as Material).depthTest = false;
  }
}
